package com.lcredu.spring.process;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author 黎长容
 * @date 2025-07-15 22:47
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    /**
     * 在bean初始化之前完成某些任务
     *
     * @param bean     : 就是ioc容器返回的的bean对象,如果这里被替代会修改,则返回的对象也会被修改
     * @param beanName : 就是 ioc 容器配置的 bean 的名称
     * @return : 就是返回的 bean 对象
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization 被调用 " + beanName + " bean= " + bean.getClass());
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization 被调用 " + beanName + " bean= " + bean.getClass());
        return bean;
    }
}
